/*
 * FXGL - JavaFX Game Library. The MIT License (MIT).
 * Copyright (c) AlmasB (almaslvl@gmail.com).
 * See LICENSE for details.
 */

package com.windea.study.kotlin.fxgl.sample.sandbox

import com.almasb.fxgl.app.*
import com.almasb.fxgl.dsl.*
import com.almasb.fxgl.dsl.components.view.*
import com.almasb.fxgl.entity.*
import com.almasb.fxgl.input.*
import javafx.scene.input.*

/**
 * @author Almas Baimagambetov (almaslvl@gmail.com)
 */
class SpriteSheetAnimationApp : GameApplication() {
	
	private var player: Entity? = null
	
	override fun initSettings(settings: GameSettings) {}
	
	override fun initGame() {
		player = entityBuilder()
			.at(200.0, 200.0)
			.with(AnimationComponent())
			.with(HealthBarViewComponent(0.0, 100.0))
			.with(StatusViewComponent())
			.buildAndAttach()
	}
	
	override fun initInput() {
		getInput().addAction(object : UserAction("Right") {
			override fun onAction() {
				player!!.getComponent(AnimationComponent::class.java).moveRight()
			}
		}, KeyCode.D)
		
		getInput().addAction(object : UserAction("Left") {
			override fun onAction() {
				player!!.getComponent(AnimationComponent::class.java).moveLeft()
			}
		}, KeyCode.A)
	}
	
	class StatusViewComponent : ChildViewComponent(0.0, 0.0, false) {
		init {
			
			val t = texture("brick.png", 16.0, 16.0)
			
			viewRoot.children.add(t)
		}
	}
}

fun main(args: Array<String>) {
	GameApplication.launch(SpriteSheetAnimationApp::class.java, args)
}
